package app.kotlin_1.base

import android.app.Activity
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import app.kotlin_1.utils.ActivityUtils
import app.kotlin_1.utils.OnMultiClickListener
import app.kotlin_1.utils.XPermissionUtils

/**
 * Created by 刘智强 on 2017/9/18.
 */

abstract class BaseActivity : AppCompatActivity(), View.OnClickListener {
    var activity: Activity? = null
    var TAG: String? = null

    init {
        activity = this;
        TAG = this.javaClass.simpleName
        ActivityUtils.addActivity(activity!!)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(getlayoutId())
        init()


    }

    fun init() {
        getData()
        initView()
        initData()
        initListenter()
        requestData()
    }


    abstract fun getlayoutId(): Int//获取页面布局ID
    abstract fun getData();//获取从其他页面获取的数据
    abstract fun initData()//初始化数据
    abstract fun initView()//初始化view
    abstract fun initListenter()//添加监听
    abstract fun requestData()//网络请求
    abstract fun setData(any: Any)//网络请求成功之后设置数据

    abstract fun setOnClick(v: View?)//点击事件

    override fun onClick(v: View?) {
//        val curClickTime = System.currentTimeMillis()
//        if (curClickTime - lastClickTime >= MIN_CLICK_DELAY_TIME) {
//            // 超过点击间隔后再将lastClickTime重置为当前点击时间
//            lastClickTime = curClickTime
//            setOnClick(v)
//        }
        setOnClick(v)


    }

    override fun onDestroy() {
        super.onDestroy()
        ActivityUtils.removeActivity(activity!!)
    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        XPermissionUtils.onRequestPermissionsResult(activity!!, requestCode, permissions as Array<String>, grantResults)
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    }


}
